package com.cskaoyan.order.biz.handler;

import com.cskaoyan.mall.dto.ClearCartItemRequest;
import com.cskaoyan.mall.dto.ClearCartItemServiceResponse;
import com.cskaoyan.order.biz.context.CreateOrderContext;
import com.cskaoyan.order.biz.context.TransHandlerContext;
import com.cskaoyan.order.dto.CartProductDto;
import com.cskaoyan.order.remote.ProductApiClient;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
public class ClearCartItemHandler extends AbstractTransHandler {


    @Autowired
    RedissonClient redissonClient;

    @Autowired
    ProductApiClient client;          //取出Feign接口 -- 用来调用carts接口

    //是否采用异步方式执行
    @Override
    public boolean isAsync() {
        return false;
    }

    @Override
    public boolean handle(TransHandlerContext context) {

        CreateOrderContext createOrderContext = (CreateOrderContext) context;

        ClearCartItemRequest request = new ClearCartItemRequest();
        request.setProductIds(createOrderContext.getBuyProductIds());
        request.setUserId(createOrderContext.getUserId());

//        client.clearCartItemByUserID(1);
        ClearCartItemServiceResponse clearCartItemServiceResponse = client.clearCartItemByUserID(request);

        System.out.println("111");
        return true;
    }
}
